//
//  FirstViewController.swift
//  Copy_Aikaopu
//
//  Created by taojianz on 2017/6/27.
//  Copyright © 2017年 taojianz. All rights reserved.
//

import UIKit
import SnapKit

class FirstViewController: BaseViewController {

    var imageView : UIImageView!
    
    var registerBtn : UIButton!
    
    var loginBtn : UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
        
    }
    // 隐藏这个页面的 navigationController
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        
        navigationController?.isNavigationBarHidden = true
    }


}
extension FirstViewController{
    
    override func setupUI() {
        super.setupUI()
        
        setupImageView()
        
        setupBtn()
        
    }
    
    func setupImageView(){
        
        imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "bg_dl")
        
        view.addSubview(imageView)
        
        imageView.snp.makeConstraints { (maker) in
            maker.width.equalToSuperview()
            maker.height.equalToSuperview()
        }
        
        
    }
    func setupBtn(){
        
        registerBtn = UIButton(type: .system)
        
        registerBtn.setTitle("创建账号", for: .normal)
        registerBtn.setTitleColor(.white, for: .normal)
        registerBtn.backgroundColor = .red
        registerBtn.sizeToFit()
        registerBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        registerBtn.layer.cornerRadius = 5
        registerBtn.addTarget(self, action: #selector(registerBtnTapped), for: .touchUpInside)
        
        
        loginBtn = UIButton(type: .system)
        
        loginBtn.setTitle("登录", for: .normal)
        loginBtn.setTitleColor(.darkGray, for: .normal)
        loginBtn.backgroundColor = .white
        loginBtn.sizeToFit()
        loginBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        loginBtn.layer.cornerRadius = 5
        
        
        view.addSubview(registerBtn)
        view.addSubview(loginBtn)
        
        registerBtn.snp.makeConstraints { (maker) in
            maker.centerX.equalToSuperview()
            maker.centerY.equalToSuperview().offset(110)
            maker.width.equalTo(UIScreen.width - 120)
        }
        
        loginBtn.snp.makeConstraints { (maker) in
            maker.centerX.equalTo(registerBtn.snp.centerX)
            maker.centerY.equalTo(registerBtn.snp.bottom).offset(40)
            maker.width.equalTo(registerBtn.snp.width)
        }
        
        loginBtn.addTarget(self, action: #selector(loginBtnTapped), for: .touchUpInside)
        
    }
    func loginBtnTapped(){
        navigationController?.pushViewController(LoginViewController(), animated: true)
    }
    func registerBtnTapped(){
        navigationController?.pushViewController(RegisterViewController(), animated: true)
        navigationController?.isNavigationBarHidden = false
    }
}
